<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form>


                    <p:panel header="1) Stock Reports" >

                        <h:panelGrid columns="2" >
                            <h:outputLabel value="Department" ></h:outputLabel>
                            <p:autoComplete completeMethod="#{departmentController.completeDept}" var="dept" itemLabel="#{dept.name}" itemValue="#{dept}" forceSelection="true" value="#{storeReportsStock.department}" converter="departmentConverter" >
                            </p:autoComplete>
                            <h:outputLabel value="Item" ></h:outputLabel>
                            <p:autoComplete  id="lstitem"   size="10" value="#{storeReportsStock.item}" 
                                             forceSelection="true"
                                             style="min-width: 223px" completeMethod="#{itemController.completeStoreItem}" 
                                             var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" >
                                <p:column headerText="Item">
                                    <h:outputLabel value="#{myItem.name}" ></h:outputLabel>
                                </p:column>
                                <p:column headerText="Code">
                                    <h:outputLabel value="#{myItem.code}" ></h:outputLabel>
                                </p:column>
                                <p:column headerText="Barcode">
                                    <h:outputLabel value="#{myItem.barcode}" ></h:outputLabel>
                                </p:column>
                            </p:autoComplete>
                            <h:outputLabel value="Item Category"/>
                            <p:autoComplete  value="#{storeReportsStock.category}" 
                                             forceSelection="true"
                                             completeMethod="#{storeItemCategoryController.completeCategory}" 
                                             var="vt" itemLabel="#{vt.name}" itemValue="#{vt}" >
                            </p:autoComplete>

                        </h:panelGrid>
                        <p:panel>
                            <p:commandButton ajax="false" value="Process" action="#{storeReportsStock.fillDepartmentStocks()}" ></p:commandButton>
                            <p:commandButton value="Print" ajax="false" >
                                <p:printer target="gpBillPreview" ></p:printer>
                            </p:commandButton>
                            <p:commandButton value="Excel" ajax="false" >
                                <pe:exporter type="xlsx" target="tbl" fileName="Total_Stock"
                                             facetBackground="#008000" facetFontSize="15" 
                                             facetFontColor="#FFFFFF" facetFontStyle="BOLD" cellFontColor="#0000FF" cellFontSize="12"  cellFontStyle="NORMAL" 
                                             fontName="Courier New" />
                            </p:commandButton>
                            <p:commandButton ajax="false" value="Process Without Stock Zero" action="#{storeReportsStock.fillDepartmentStocksWithOutStockZero()}" ></p:commandButton>
                            <p:commandButton value="Excel Without Stock Zero" ajax="false">
                                <pe:exporter type="xlsx" target="tbl" fileName="Total_Stock_with_out_zero" 
                                             facetBackground="#008000" facetFontSize="15" 
                                             facetFontColor="#FFFFFF" facetFontStyle="BOLD" cellFontColor="#0000FF" cellFontSize="12"  cellFontStyle="NORMAL" 
                                             fontName="Courier New" />
                            </p:commandButton>
                        </p:panel>

                        <h:panelGroup id="gpBillPreview"  styleClass="noBorder summeryBorder" style="min-width: 100%!important;">

                            <p:dataTable id="tbl" rowIndexVar="ii"  value="#{storeReportsStock.stocks}" var="i"  >
                                <f:facet name="header">
                                    <h:outputLabel value="#{storeReportsStock.department.name} : Department Stock By Batch"/> 
                                    <h:outputLabel value="#{storeReportsStock.category.name}"  style=" white-space:pre-line;"/> 
                                    <h:outputLabel value="&emsp;&emsp;#{storeReportsStock.item.name} "/>
                                </f:facet> 

                                <p:column>
                                    <h:outputLabel value="#{ii+1}" />
                                </p:column>

                                <p:column headerText="Item Code">
                                    <f:facet name="header">
                                        <h:outputLabel value="Item"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.item.name}" style="width: 100px!important;" ></h:outputLabel>
                                </p:column>

                                <p:column headerText="Item Code">
                                    <f:facet name="header">
                                        <h:outputLabel value="Item code"/>
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.item.code}" ></h:outputLabel>
                                </p:column>                                

                                <p:column headerText="Quantity" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Quantity"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.stock}"  >
                                    </h:outputLabel>                                 
                                </p:column>

                                <p:column headerText="Expiry">
                                    <f:facet name="header">
                                        <h:outputLabel value="Expiry"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.dateOfExpire}"  >
                                        <f:convertDateTime pattern="MM/yy" ></f:convertDateTime>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Batch No">
                                    <f:facet name="header">
                                        <h:outputLabel value="Batch No"/>    
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.batchNo}"  >                                        
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Purchase Rate" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Purchase Rate"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.purcahseRate}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Purchase Value" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Purchase Value"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.purcahseRate * i.stock}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Retail Price" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Retail Price"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.retailsaleRate}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>

                                <p:column headerText="Retail Sale Value" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Retail Sale Value"/>                                     
                                    </f:facet>
                                    <h:outputLabel value="#{i.itemBatch.retailsaleRate * i.stock}"  >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                </p:column>
                                <p:columnGroup type="footer">
                                    <p:row>
                                        <p:column colspan="6" footerText="Total">
                                            <f:facet name="footer">
                                                <h:outputLabel value="Total" />
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" footerText="#{storeReportsStock.stockPurchaseValue}">
                                            <f:facet name="footer" >
                                                <h:outputLabel value="#{storeReportsStock.stockPurchaseValue}" >
                                                    <f:convertNumber parent="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column></p:column>
                                        <p:column style="text-align: right;" footerText="#{storeReportsStock.stockSaleValue}">
                                            <f:facet name="footer" >
                                                <h:outputLabel value="#{storeReportsStock.stockSaleValue}" >
                                                    <f:convertNumber parent="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                    </p:row>
                                </p:columnGroup>
                                <f:facet name="footer" >
                                    <h:outputLabel value="Printed By : #{sessionController.loggedUser.webUserPerson.name}" style="float: right"/>
                                </f:facet>

                            </p:dataTable>
                        </h:panelGroup>
                    </p:panel>
                </h:form>


            </ui:define>


        </ui:composition>

    </h:body>
</html>
